// pages/forum/forum.js
//获取应用实例
const app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    imgs: null, //本地图片地址
    treeData: null, //树洞数据
    banner: [
      "/images/homePage/logo.jpg",
      "/images/homePage/tltie.png",
      "/images/homePage/tltie2.png",
      "/images/homePage/tltie3.jpg",
    ],
    word: "",
    background: ["red", "pink", "yellowgreen"],
    indicatorDots: true,
    vertical: false,
    autoplay: true,
    interval: 5000,
    duration: 500,
    circular: true,
    select: false,
    grade_name: '分类',
    grades: [{
        id: 0,
        name: '全部',
      },
      {
        id: 1,
        name: '闲聊',
      },
      {
        id: 2,
        name: '吐槽',
      },
      {
        id: 3,
        name: '表白',
      },
      {
        id: 4,
        name: '捞人',
      },
    ],
    grades_loge: '/images/homePage/xia.pngs'
  },
  bindShowMsg() {
    this.setData({
      select: !this.data.select
    })
  },
  //----------------------------查询所有文章-------------------------------
  chatRelease(){
    var that = this;
    if (!app.globalData.hasLogin) {
      wx.showModal({
        title: '提示',
        content: '你还没有登录喔',
        success: function (res) {
          if (res.confirm) { //这里是点击了确定以后
            wx.switchTab({
              url: '/pages/own/own',
            })
          } else { //这里是点击了取消以后
            that.errShowToast('你还没有登录喔');
          }
        }
      })
      return;
    }
    wx.navigateTo({
      url:'/pages/chatRelease/chatRelease'
    })
  },

  //-------------------------排序-----------------

  //获取输入框的内容
  houduanTab_input: function (e) {
    // console.log(e.detail.value);
    this.setData({
      word: e.detail.value
    })
  },

  //-----------------------------分类查找---------------------------------------
  mySelect(e) {
    var name = e.currentTarget.dataset.name
    var that = this;
    this.setData({
      grade_name: name,
      select: false
    })
    // console.log(e.currentTarget.id);
    wx.request({
      url: app.globalData.myUrl + '/tree/list',
      data: {
        'classify': e.currentTarget.id,
      },
      method: 'GET',
      success: (res) => {
        // console.log(res.data);
        if (res.data.success) {
          that.setData({
            treeData: res.data.msg
          });
        } else {
          that.errShowToast(res.data.msg);
        }
      },
      fail: (res) => {},
    })
  },

  //----------------------------查询所有文章-------------------------------
  listTree() {
    var that = this;
    wx.request({
      url: app.globalData.myUrl + '/tree/list',
      method: 'GET',
      success: (res) => {
        // console.log(res.data);
        if (res.data.success) {
          that.setData({
            treeData: res.data.msg
          });
        } else {
          that.errShowToast(res.data.msg);
        }
      },
      fail: (res) => {},
    })
  },

  //-------------------------获取指定文章详情----------------------------
  getTree(e) {
    wx.navigateTo({
      url: '/pages/chatDetailed/chatDetailed?id=' + e.currentTarget.id
    })
  },

  //---------------------------函数封装------------------------------
  errShowToast: function (toastText) {
    wx.showToast({
      title: toastText,
      image: '/images/password.png',
      duration: 2000
    });
  },
  sucShowToast: function (toastText) {
    wx.showToast({
      title: toastText,
      duration: 2000
    });
  },



  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    this.listTree();
    this.setData({
      grade_name: '分类'
    })
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
    this.listTree();
    this.setData({
      grade_name: '分类'
    })
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },
  /**
   * 分享到朋友圈
   */
  // onShareTimeline: function() {
  //   return {
  //     title: '一个小demo',
  //     imageUrl: "https://www.kongbai121.xyz/drawing-bed/2023-01/59e40761-c197-4b17-be36-bfbd1f2cfa1c.jpg"
  //   }
  // },
  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
    return {
      title: '一个小demo',
      path: '/pages/loading/loading',
      imageUrl: "https://www.kongbai121.xyz/drawing-bed/2023-01/59e40761-c197-4b17-be36-bfbd1f2cfa1c.jpg"
    }
  }
})